package com.molyfun.parents.activity.schoolonline.homework.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class DateChooseView extends LinearLayout implements View.OnClickListener{

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.left_arrow)
    ImageView mLeftArraw;
    @InjectView(R.id.right_arrow)
    ImageView mRightArraw;
    @InjectView(R.id.current_time)
    TextView mCurrentTime;



    public DateChooseView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public DateChooseView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public DateChooseView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_date_choose, this);
        ButterKnife.inject(this);
        mLeftArraw.setOnClickListener(this);
        mRightArraw.setOnClickListener(this);
        mCurrentTime.setOnClickListener(this);
    }

    public void setDate(String date){
        mCurrentTime.setText(date);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.left_arrow:
                if(mDateChooseViewCallback != null){
                    mDateChooseViewCallback.onDayPreClick();
                }
                break;
            case R.id.right_arrow:
                if(mDateChooseViewCallback != null){
                    mDateChooseViewCallback.onDayNextClick();
                }
                break;
            case R.id.current_time:
                if(mDateChooseViewCallback != null){
                    mDateChooseViewCallback.onDateClick();
                }
                break;
        }
    }

    private DateChooseViewCallback mDateChooseViewCallback;

    public void setDateChooseViewCallback(DateChooseViewCallback dateChooseViewCallback){
        this.mDateChooseViewCallback = dateChooseViewCallback;
    }

    public interface DateChooseViewCallback{
        public void onDayPreClick();
        public void onDateClick();
        public void onDayNextClick();
    }

}